﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using System.Data.Linq;
using Model;
using DAL;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            //HouseholdDAL dal = new HouseholdDAL();

            //var list = dal.SelectAll();
            //list.ForEach(x =>
            //{
            //    Console.WriteLine(x.ID + "\t" + x.Address + "\t" + x.Type);
            //});
            //Console.ReadLine();
            //return;

            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite.EF6");
            DbConnection connection = fact.CreateConnection();
            connection.ConnectionString = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "database\\ServiceCenter.db";
            connection.Open();

            DataStorage database = new DataStorage(connection);

            database.Areas.Add(new Area { Name = "测试001" });
            database.SaveChanges();
            var list = database.Areas.ToList();
            list.ForEach(x =>
            {
                Console.WriteLine(x.ID + "\t" + x.Name + "\t" + x.ParentID);
            });

            database.Nations.Add(new Nation { Name = "测试000" });
            database.SaveChanges();
            var nations = database.Nations.ToList();
            nations.ForEach(x =>
            {
                Console.WriteLine(x.ID + "\t" + x.Name);
            });

            database.Persons.Add(new Person { Name = "周攀峰", Address = "ada", AreaID = Guid.NewGuid(), Birthday = DateTime.Now, NationID = 1, PhotoURI = "aaa", PIN = "123456789", PoliticalStatusID = 1 });
            database.SaveChanges();
            var persons = database.Persons.ToList();
            persons.ForEach(x =>
            {
                Console.WriteLine(x.ID + "\t" + x.Name);
            });

            database.Dispose();
            Console.ReadLine();
            return;

            DbCommand command = fact.CreateCommand();
            command.Connection = connection;
            command.CommandText = "select * from category";

            DbDataAdapter adapter = fact.CreateDataAdapter();
            adapter.SelectCommand = command;
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            adapter.Dispose();

            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                foreach (DataColumn col in dataSet.Tables[0].Columns)
                {
                    Console.Write(row[col] + " ");
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}
